﻿Option Strict On
Option Explicit On 

Imports IP.Core.IPCommon
Imports System.Windows.forms

''' -----------------------------------------------------------------------------
''' Project	 : IPDataControl
''' Class	 : Core.IPDataControl.DEFormUtils
''' 
''' -----------------------------------------------------------------------------
''' <summary>
''' Các tiện ích cho form DE
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' 	[csung]	3/8/2005	Created
''' </history>
''' -----------------------------------------------------------------------------
Public Class DEFormUtils

#Region "PUBLIC"

    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="i_frm"></param>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' 	[csung]	3/8/2005	Created
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public Shared Sub disable_conrols_in_form(ByVal i_frm As Form)
        Dim v_container As New ControlContainer(i_frm)
        disable_all_control_recursive(v_container)
    End Sub

    Public Shared Sub disable_controls_in_panel(ByVal i_panel As Panel)
        Dim v_container As New ControlContainer(i_panel)
        disable_all_control_recursive(v_container)

    End Sub

    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="i_frm"></param>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' 	[csung]	3/8/2005	Created
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public Shared Sub enable_controls_in_form(ByVal i_frm As Form)
        Dim v_container As New ControlContainer(i_frm)
        enable_all_control_recursive(v_container)
    End Sub
    Public Shared Sub enable_controls_in_panel(ByVal i_panel As Panel)
        Dim v_container As New ControlContainer(i_panel)
        enable_all_control_recursive(v_container)
    End Sub
#End Region

#Region "Private"
    Private Shared Sub disable_all_control_recursive(ByVal i_container As ControlContainer)
        Dim v_ctl As Control
        For Each v_ctl In i_container.getControls
            Dim v_str_type As String = v_ctl.GetType.ToString
            If v_str_type = "System.Windows.Forms.TextBox" Then
                Dim v_txtbox As TextBox = CType(v_ctl, TextBox)
                v_txtbox.ReadOnly = True
            ElseIf v_str_type = "System.Windows.Forms.CheckBox" Then
                v_ctl.Enabled = False
            ElseIf v_str_type = "System.Windows.Forms.ComboBox" Then
                v_ctl.Enabled = False
            ElseIf v_str_type = "C1.Win.C1FlexGrid.C1FlexGrid" Then
                v_ctl.Enabled = False
            ElseIf v_str_type = "System.Windows.Forms.Panel" Then
                Dim v_pnl As Panel = CType(v_ctl, Panel)
                Dim v_pnl_container As New ControlContainer(v_pnl)
                disable_all_control_recursive(v_pnl_container)
            ElseIf v_str_type = "System.Windows.Forms.GroupBox" Then
                Dim v_grp As GroupBox = CType(v_ctl, GroupBox)
                Dim v_grp_container As New ControlContainer(v_grp)
                disable_all_control_recursive(v_grp_container)
            End If
        Next
    End Sub

    Private Shared Sub enable_all_control_recursive(ByVal i_container As ControlContainer)
        Dim v_ctl As Control
        For Each v_ctl In i_container.getControls
            Dim v_str_type As String = v_ctl.GetType.ToString
            If v_str_type = "System.Windows.Forms.TextBox" Then
                Dim v_txtbox As TextBox = CType(v_ctl, TextBox)
                v_txtbox.ReadOnly = False
            ElseIf v_str_type = "System.Windows.Forms.CheckBox" Then
                v_ctl.Enabled = True
            ElseIf v_str_type = "System.Windows.Forms.ComboBox" Then
                v_ctl.Enabled = True
            ElseIf v_str_type = "C1.Win.C1FlexGrid.C1FlexGrid" Then
                v_ctl.Enabled = True
            ElseIf v_str_type = "System.Windows.Forms.Panel" Then
                Dim v_pnl As Panel = CType(v_ctl, Panel)
                Dim v_pnl_container As New ControlContainer(v_pnl)
                disable_all_control_recursive(v_pnl_container)
            ElseIf v_str_type = "System.Windows.Forms.GroupBox" Then
                Dim v_grp As GroupBox = CType(v_ctl, GroupBox)
                Dim v_grp_container As New ControlContainer(v_grp)
                disable_all_control_recursive(v_grp_container)
            End If
        Next
    End Sub

#End Region

    
End Class
